<template>
  <div class="" style="height:100%;">
    <div class="days f14 ub  padding-css3 ">
      <div class="daysdiv ub ub-ac" id="qian" @click="changeDate(1)">
        <img class="img1 ub ub-ac " alt="" src="./arrow_left@2x.png">
        <span class="qian">前一天</span>
      </div>
      <div class="daysdiv2 fontWei ub-f1 ub ub-ac ub-pc">
        <span class="datatime">{{today}}</span>
        <span class="margin-l-css2 zhou">{{todayDate}}</span>
      </div>
      <div class="daysdiv ub ub-ac ub-pe" @click="changeDate(2)" id="hou">
        <span class="hou">后一天</span>
        <img class="img1 ub ub-ac " alt="" src="./arrow_right@2x.png">
      </div>
    </div>
    <div class="padding-css2 bg-F2">
      <div class="ub ub-fh  f14 todaylist">
        <div class="ub ub-ac jrdiv ">航班号</div>
        <div class="ub ub-ac jrdiv">计划起降</div>
        <div class="ub ub-ac jrdiv ">实际起降</div>
        <div class="ub ub-ac jrdiv ub-pe">状态</div>
      </div>
    </div>
    <div :key="index" v-for="(item,index) in flightlist" @click="opendata(item)" class="padding-css2  f14  bg-white dongtai ub ub-ver">
      <div class="ub ub-fh ub-ver border-botttom padding-css6 f14 xiangqing">
        <div class="ub ub-fh ">
          <div class="ub ub-ac jrdiv ">{{item.flightNo}}</div>
          <div class="ub ub-ac jrdiv">{{item.etd.substr(11,5)||'--:--'}}</div>
          <div class="ub ub-ac jrdiv">{{item.atdChn.substr(11,5)||'--:--'}}</div>
          <div class="ub ub-ac jrdiv ub-pe daoda">{{item.flightState}}</div>
        </div>
        <div class="ub ub-fh ">
          <div class="ub ub-ac jrdiv "></div>
          <div class="ub ub-ac jrdiv">{{item.eta.substr(11,5)||'--:--'}}</div>
          <div class="ub ub-ac jrdiv">{{item.ataChn.substr(11,5)||'--:--'}}</div>
          <div class="ub ub-ac jrdiv ub-pe"></div>
        </div>
      </div>
    </div>
  </div>
</template>
<script type="text/ecmascript-6">
import { mapState } from 'vuex';
export default {
  created: function () {
    let self = this;
    this.$store.commit('changeHeader', { // 提交首页header
      left: '返回',
      right: '',
      middle: '航班动态',
      ifshow: true,
      leftAction: '-1',
      leftIcon: 'leftIcon',
      rightAction: '',
      rightIcon: ''
    });
    this.nowDate = new Date(this.airDynamic.data.time);
    self.today = ((this.nowDate.getMonth() + 1) < 10 ? '0' + (this.nowDate.getMonth() + 1) : (this.nowDate.getMonth() + 1)) + '-' + (this.nowDate.getDate() < 10 ? '0' + this.nowDate.getDate() : this.nowDate.getDate())
    self.todayDate = self.getday(this.nowDate.getDay());
    console.log(this.airDynamic);
    this.getdata('')
  },
  data: function () {
    return {
      today: '',
      todayDate: '',
      nowDate: '',
      flightlist: []
    }
  },
  components: {
  },
  methods: {
    opendata: function (item) {
      console.log(item)
      this.$store.commit('setAirDynamicFindjg', item)
      this.$router.push('/airDynamic_findjg');
    },
    changeDate: function (type) {
      let self = this;
      if (type === 1) { // 前一天
        this.nowDate = new Date(new Date((this.nowDate.getFullYear()) + '/' + (this.nowDate.getMonth() + 1) + '/' + this.nowDate.getDate()).getTime() - 1000 * 24 * 3600 * 1);
        self.today = ((this.nowDate.getMonth() + 1) < 10 ? '0' + (this.nowDate.getMonth() + 1) : (this.nowDate.getMonth() + 1)) + '-' + (this.nowDate.getDate() < 10 ? '0' + this.nowDate.getDate() : this.nowDate.getDate())
        self.todayDate = self.getday(this.nowDate.getDay());
      } else {
        this.nowDate = new Date(new Date((this.nowDate.getFullYear()) + '/' + (this.nowDate.getMonth() + 1) + '/' + this.nowDate.getDate()).getTime() + 1000 * 24 * 3600 * 1);
        self.today = ((this.nowDate.getMonth() + 1) < 10 ? '0' + (this.nowDate.getMonth() + 1) : (this.nowDate.getMonth() + 1)) + '-' + (this.nowDate.getDate() < 10 ? '0' + this.nowDate.getDate() : this.nowDate.getDate())
        self.todayDate = self.getday(this.nowDate.getDay());
      }
      let time = this.nowDate.getFullYear() + '-' + self.today;
      this.getdata(time)
    },
    getdata: function (time) {
      let self = this;
      let content = {}
      let times = time
      if (this.airDynamic.data.type === 1) {
        content = {
          'airlineCode': this.airDynamic.data.airCM,
          'airlineRadio_value': 'HB',
          'depDate': time ? times : this.airDynamic.data.time,
          'fltNum': this.airDynamic.data.flightNum
        }
      } else {
        content = {
          'arr': this.airDynamic.data.arr,
          'airlineRadio_value': 'XX',
          'dep': this.airDynamic.data.dep,
          'depDate': time ? times : this.airDynamic.data.time
        }
      }
      let data = this.$utils.getUserContent(content);
      this.$store.commit('showLoading');
      this.$http.post(this.$RS.findDynamic, data).then(
        function (res) {
          // 响应成功回调
          self.$store.commit('closePop');
          res = res.body;
          console.log(res)
          if (res.code === 1000) {
            self.flightlist = res.content;
          } else {
            self.$store.dispatch('showTx', { text: res.message || '网络错误，请重试' });
          }
        },
        function (err) {
          self.$store.commit('closePop');
          // 响应错误回调
          self.$store.dispatch('showTx', { text: '网络错误，请重试' });
        }
      );
    },
    getday: function (date) {
      switch (date) {
        case 0:
          return '周日';
          break;
        case 1:
          return '周一';
          break;
        case 2:
          return '周二';
          break;
        case 3:
          return '周三';
          break;
        case 4:
          return '周四';
          break;
        case 5:
          return '周五';
          break;
        case 6:
          return '周六';
          break;
      }
    }
  },
  computed: mapState(['loginData', 'airDynamic', 'airDynamicFindjg'])
}
</script>
<style lang="stylus">
@import '../../stylus/base.styl';
@import '../../../static/zyh.styl';
.padding-css3
  padding: f_times(0.8) f_times(0.8);
.days div
  height: f_times(2.5);
.daysdiv2
  border-radius: f_times(2.4);
  color: white;
  background-color: #843D99;
  margin: 0 f_times(0.8);
.img1
  width: 1.6rem;
.fontWei
  font-weight: 800;
.padding-css2
  padding: 0 f_times(0.8);
.bg-F2
  background-color: #F2F2F2;
.todaylist div
  height: f_times(3);
.jrdiv
  width: 25%;
.border-botttom
  border-bottom: 2px solid #EEEEEE;
.padding-css6
  padding: f_times(0.8) 0;
.daoda
  color: #843D99;
.jihua
  color: #009EFF;
.c-lor1
  color: #6BAB76;
.yanwu
  color: #FFB134;
.quxiao
  color: red;
</style>